package models;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import play.db.ebean.Model;

/*
 * Encapsulates the Order.
 * Author: Uldana Mamirey
 */

@Entity
public class UserOrder extends Model {

	@Id
	public Long id;
	
	@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	public User user;
	
	@Column(nullable = true)
	@OneToMany(mappedBy = "userOrder", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	public List<CartItem> items;
	
	public Integer status;
	
	public static Finder<Long, UserOrder> find = new Finder<Long, UserOrder>(Long.class, UserOrder.class);
	
	public static UserOrder create(User user)
	{
		UserOrder userOrder = new UserOrder();
		userOrder.user = user;
		return userOrder;
	}
}